<template>
  <div class="app-container">
    <div class="page-header">
      <div class="back-button">
        <el-button
          @click="
            $router.push('/main/renshi/zhaoping/gongzuobxhpb/gongzuobxhpb')
          "
          icon="el-icon-back"
          >返回</el-button
        >
      </div>
      <h1>工作表现评核表列表</h1>
    </div>
    <!-- 搜索栏 -->
    <div class="filter-container">
      <el-input
        v-model="listQuery.employeeId"
        placeholder="工号"
        style="width: 200px"
        class="filter-item"
        @keyup.enter.native="handleFilter"
      />
      <el-input
        v-model="listQuery.name"
        placeholder="姓名"
        style="width: 200px"
        class="filter-item"
        @keyup.enter.native="handleFilter"
      />
      <el-input
        v-model="listQuery.department"
        placeholder="部门"
        style="width: 200px"
        class="filter-item"
        @keyup.enter.native="handleFilter"
      />
      <el-button
        class="filter-item"
        type="primary"
        icon="el-icon-search"
        @click="handleFilter"
      >
        搜索
      </el-button>
      <el-button
        class="filter-item"
        type="primary"
        icon="el-icon-plus"
        @click="handleCreate"
      >
        新增
      </el-button>
    </div>

    <!-- 表格 -->
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
    >
      <el-table-column label="工号" prop="employeeId" align="center" />
      <el-table-column label="姓名" prop="name" align="center" />
      <el-table-column label="部门" prop="department" align="center" />
      <el-table-column label="职务" prop="position" align="center" />
      <el-table-column label="入厂日期" align="center">
        <template slot-scope="scope">
          {{ scope.row.entryDate | formatDate }}
        </template>
      </el-table-column>
      <el-table-column label="表现总评" align="center">
        <template slot-scope="scope">
          <el-tag :type="getEvaluationTagType(scope.row.overallEvaluation)">
            {{ getEvaluationText(scope.row.overallEvaluation) }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="230">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleView(scope.row)">查看</el-button>
          <el-button size="mini" type="primary" @click="handleUpdate(scope.row)"
            >编辑</el-button
          >
          <el-button size="mini" type="danger" @click="handleDelete(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { getPageApi, removeApi } from "@/api/gongzuobxhpb";
import Pagination from "@/components/Pagination";
import { formatDate } from "@/utils/date";

export default {
  name: "GongzuobxhpbList",
  components: { Pagination },
  filters: {
    formatDate(date) {
      return formatDate(date);
    },
  },
  data() {
    return {
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 10,
        employeeId: undefined,
        name: undefined,
        department: undefined,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    async getList() {
      this.listLoading = true;
      try {
        const data = await getPageApi(this.listQuery);
        console.log(data);
        this.list = data.data.data.records;
        this.total = data.data.data.total;
      } catch (error) {
        console.error("获取列表失败：", error);
      }
      this.listLoading = false;
    },
    handleFilter() {
      this.listQuery.page = 1;
      this.getList();
    },
    handleCreate() {
      this.$router.push("/main/renshi/zhaoping/gongzuobxhpb/gongzuobxhpb");
    },
    handleView(row) {
      this.$router.push({
        path: "/main/renshi/zhaoping/gongzuobxhpb/gongzuobxhpb",
        query: { mode: "view", id: row.id },
      });
    },
    handleUpdate(row) {
      this.$router.push({
        path: "/main/renshi/zhaoping/gongzuobxhpb/gongzuobxhpb",
        query: { mode: "edit", id: row.id },
      });
    },
    handleDelete(row) {
      this.$confirm("确认删除该记录？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          try {
            await removeApi(row.id);
            this.$message.success("删除成功");
            this.getList();
          } catch (error) {
            console.error("删除失败：", error);
          }
        })
        .catch(() => {});
    },
    getEvaluationText(value) {
      const map = {
        1: "未能接受",
        2: "可以接受",
        3: "全面接受/好",
        4: "良好",
        5: "极好",
      };
      return map[value] || "未评价";
    },
    getEvaluationTagType(value) {
      const map = {
        1: "danger",
        2: "warning",
        3: "success",
        4: "success",
        5: "success",
      };
      return map[value] || "info";
    },
  },
};
</script>

<style scoped lang="scss">
.app-container {
  padding: 20px;
  width: 1200px;
  margin: 0 auto;
  min-height: calc(100vh - 40px);
}
.page-header {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 30px;
  padding: 20px;
  position: relative;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);

  h1 {
    font-size: 24px;
    color: #2c3e50;
    margin: 0;
    font-weight: 600;
    position: relative;
    padding-bottom: 10px;

    &::after {
      content: "";
      position: absolute;
      bottom: 0;
      left: 50%;
      transform: translateX(-50%);
      width: 60px;
      height: 3px;
      background: linear-gradient(90deg, #409eff, #67c23a);
      border-radius: 3px;
    }
  }
}
.back-button {
  position: absolute;
  left: 20px;
  top: 50%;
  transform: translateY(-50%);
}
.filter-container {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 30px;
  padding: 20px;
  position: relative;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
}
.filter-item {
  margin-right: 10px;
}
</style> 